/*
 * test1
 */
package com.pitop.errortype.ctrl;


import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.errortype.entity.ErrortypeLocal;
import com.pitop.errortype.service.ErrortypeLocalSVImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 错误类型本地化 控制器
 *
 * @author test1
 */
@RestController
@RequestMapping("/errortypeLocal")
@Slf4j
@Api(value = "错误类型本地化控制器", description = "错误类型本地化控制器")
public class ErrortypeLocalCtrl {

    @Resource
    protected RedisUtils redisUtils;
    @Autowired
    private ErrortypeLocalSVImpl errortypeLocalSVImpl;


    /**
     * 查询ErrortypeLocal一个详情信息
     *
     * @param id
     * @param errorTypeCode 错误类型编码
     * @param language      语言
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id, String errorTypeCode, String language) {
        if (id == null) {
            return BeanRet.create(false, BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isBlank(errorTypeCode)) {
            return BeanRet.create(false, BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isBlank(language)) {
            return BeanRet.create(false, BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSVImpl.load(id, errorTypeCode, language);
        log.info(JSON.toJSONString(errortypeLocal));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }


    /**
     * 根据条件id查询ErrortypeLocal一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null || id == 0) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSVImpl.loadById(id);
        log.info(JSON.toJSONString(errortypeLocal));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }

    /**
     * 根据条件errorTypeCode查询ErrortypeLocal一个详情信息
     *
     * @param errorTypeCode 错误类型编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/errorTypeCode/{errorTypeCode}")
    @ResponseBody
    public BeanRet loadByErrorTypeCode(@PathVariable String errorTypeCode) {
        if (StringUtils.isEmpty(errorTypeCode)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSVImpl.loadByErrorTypeCode(errorTypeCode);
        log.info(JSON.toJSONString(errortypeLocal));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }

    /**
     * 根据条件language查询ErrortypeLocal一个详情信息
     *
     * @param language 语言
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "language", value = "语言", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/language/{language}")
    @ResponseBody
    public BeanRet loadByLanguage(@PathVariable String language) {
        if (StringUtils.isEmpty(language)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSVImpl.loadByLanguage(language);
        log.info(JSON.toJSONString(errortypeLocal));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }


    /**
     * 查询ErrortypeLocal信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ErrortypeLocal信息集合", notes = "查询ErrortypeLocal信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),

    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore ErrortypeLocal errortypeLocal, @ApiIgnore Page<ErrortypeLocal> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<ErrortypeLocal> errortypeLocals = errortypeLocalSVImpl.list(errortypeLocal, page.getCurPage(), page.getPageSize());
        int total = errortypeLocalSVImpl.count(errortypeLocal);
        page.setTotalRow(total);
        page.setVoList(errortypeLocals);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }


    /**
     * 查询ErrortypeLocal信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ErrortypeLocal信息集合", notes = "查询ErrortypeLocal信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, String errorTypeCode, String language, @ApiIgnore Page<ErrortypeLocal> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<ErrortypeLocal> errortypeLocals = errortypeLocalSVImpl.list(id, errorTypeCode, language, page.getCurPage(), page.getPageSize());
        int total = errortypeLocalSVImpl.count(id, errorTypeCode, language);
        page.setTotalRow(total);
        page.setVoList(errortypeLocals);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
     * 创建ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ErrortypeLocal", notes = "创建ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "文本对照", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore ErrortypeLocal errortypeLocal) {
        if (StringUtils.isEmpty(errortypeLocal.getErrorTypeCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errortypeLocal.getLanguage())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errortypeLocal.getInfo())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        errortypeLocalSVImpl.save(errortypeLocal);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }


    /**
     * 修改ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ErrortypeLocal", notes = "修改ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "文本对照", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore ErrortypeLocal errortypeLocal) {
        if (StringUtils.isEmpty(errortypeLocal.getErrorTypeCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errortypeLocal.getLanguage())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(errortypeLocal.getInfo())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        errortypeLocalSVImpl.modify(errortypeLocal);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, errortypeLocal);
    }

    /**
     * 根据主键删除ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ErrortypeLocal", notes = "删除ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String errorTypeCode, String language) {
        if (id != null && StringUtils.isEmpty(errorTypeCode) && StringUtils.isEmpty(language)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }

        errortypeLocalSVImpl.delete(id, errorTypeCode, language);
        return BeanRet.create(true, "删除ErrortypeLocal成功");
    }


}
